package com.test.mytest.swing;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.test.mytest.swt.User;

public class UserTableModel extends AbstractTableModel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	List<User> list=new ArrayList<>();
	String[] names=new String[]{"用户名","性别","年龄"};		

	@Override
	public int getRowCount() {
		return list.size();
	}

	@Override
	public int getColumnCount() {
		return names.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		User user = list.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return user.getName();
		case 1:
			return user.getSex();
		case 2:
			return user.getAge();
		}
		return null;
	}
	@Override
	public String getColumnName(int column) {
		return names[column];
	}

	public List<User> getList() {
		return list;
	}

	public void setList(List<User> list) {
		this.list = list;
		fireTableStructureChanged();
	}
}
